﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shifa
{
    class Question
    {
        private string key;
        private bool comment_only;
        private List<int> ratings;
        private List<string> comments;

        public Question(string key)
        {
            this.key = key;
            this.comment_only = false;
            this.ratings = new List<int>();
            this.comments = new List<string>();
        }
        
        public Question(string key, bool comment_only)
        {
            this.key = key;
            this.comment_only = comment_only;
            this.ratings = new List<int>();
            this.comments = new List<string>();
        }

        public string Key
        {
            get { return this.key; }
        }
        
        public bool CommentOnly
        {
            get { return this.comment_only; }
        }

        public List<int> Ratings
        {
            get { return this.ratings; }
            set { this.ratings = value; }
        }
        
        public List<string> Comments
        {
            get { return this.comments; }
            set { this.comments = value; }
        }

        public double GetAverage()
        {
            double average = 0.0;
            foreach (int val in this.ratings)
            {
                average += val;
            }
            average = average / this.ratings.Count;

            return average;
        }
        
        public string GetComments()
        {
        	string comments = "";
        	foreach(string comment in this.comments)
        	{
        		comments = comments + "<li>" + comment + "</li>";
        	}
        	
        	if (comments == "") 
        	{
        		return "<i>No comments found.</i>";
        	} else {
        		return "<ol>" + comments + "</ol>";
        	}
        }

        public override bool Equals(object obj)
        {
            Question temp = (Question)obj;
            if (temp.key == this.key)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public override string ToString()
        {
            return this.key;
        }
    }
}
